package decisionLines.view;

import java.awt.Canvas;
import java.awt.Graphics;

import decisionLines.model.DecisionLinesEvent;

/**
 * Class to draw the lines and edges on the Application (frame) GUI
 */
public class DrawingCanvas extends Canvas {
	/** Decision Lines Event which will be displayed */
	DecisionLinesEvent event;
	
	/**
	 * Constructor: DrawingCanvas
	 * @param e - The Decision Lines Event to display (DecisionLinesEvent)
	 */
	public DrawingCanvas (DecisionLinesEvent e) {
		super ();
		
		this.event = e;
	}
	
	/**
	 * Method: Provide the X location of the Line at specified position (i.e., 0 - 8).
	 * @param n - Indicates the position of the line (int)
	 * @return - The X location of the line (int)
	 */
	public int lineXlocation (int n) {
		return 100*n+50;
	}
	
	/**
	 * Method: Provide the Y location of the Line at specified position (i.e., 0 - 8).
	 * @param n - Indicates the position of the line (int)
	 * @return - The Y location of the line (int)
	 */
	public int lineYlocation (int n) {
		return 10;
	}
	
	/**
	 * Method: Provide the width of the Line at specified position (i.e., 0 - 8).
	 * @param n - Indicates the position of the line (int)
	 * @return - The width of the line (int)
	 */
	public int lineWidth(int n) {
		return 3;
	}
	
	/**
	 * Method: Provide the height of the Line at specified position (i.e., 0 - 8).
	 * @param n - Indicates the position of the line (int)
	 * @return - The height of the line (int)
	 */
	public int lineHeight(int n) {
		return 350;
	}
	
	/**
	 * Method: Draw the lines on the panel using filled rectangles
	 * @param g - the graphics object containing the lines (Graphics)
	 */
	public void paint (Graphics g) {
		for (int i = 0; i < event.getNumChoices(); i++){
			g.fillRect(lineXlocation(i), lineYlocation(i), lineWidth(i), lineHeight(i));
			int h = 0;
			while (event.getLines().get(i).nextEdge(h) != null){
				g.drawLine(lineXlocation(event.getLines().get(i).nextEdge(h).getLeft()),
						event.getLines().get(i).nextEdge(h).getHeight(), 
						lineXlocation(event.getLines().get(i).nextEdge(h).getRight()), 
						event.getLines().get(i).nextEdge(h).getHeight());
				h = event.getLines().get(i).nextEdge(h).getHeight();
			}
		}
	}
}
